package com.chuan.thinkingjava.think1;

public class Demo1 {
	
	private static final String REG_STR_IOS = "IOS";
	private static final String REG_STR_APPLE = "APPLE";
	private static final String REG_STR_MEDIAPLAYER = ".*mediaplayer.*";
	
	public static void main(String[] args) {
		try {
			System.out.println(filter("sdsaIaappLEioS"));
		} catch (Exception ex) {
			System.out.println(ex.getMessage());
		}
	}
	
	public static String filter(String str) throws Exception {
		String result = "";
		if (str != null && !("").equals(str)) {
			if (!str.matches(REG_STR_MEDIAPLAYER)) {
				
				int index_ios = str.toUpperCase().indexOf(REG_STR_IOS);
				int index_apple = str.toUpperCase().indexOf(REG_STR_APPLE);
				if ((index_ios != -1) && (index_apple != -1)) {
					result = str.substring(index_ios, (index_ios+3))+"/" + " " + str.substring(index_apple, (index_apple+5));
				} else if ((index_ios != -1) && !(index_apple != -1)) {
					result = str.substring(index_ios, (index_ios+3))+"/";
				} else if (!(index_ios != -1) && (index_apple != -1)) {
					result = str.substring(index_apple, (index_apple+5));
				} else {
					System.out.println("传入的字符串str不包含“ios”和“apple”");
				}
			}
		} else {
			throw new Exception("不能传入空字符串");
		}
		return result;
	}
}
